package com.baizhi.service.impl;

import com.baizhi.dao.FollowingDao;
import com.baizhi.entity.Following;
import com.baizhi.service.FollowingService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * 关注(Following)表服务实现类
 *
 * @author makejava
 * @since 2021-09-26 23:06:57
 */
@Transactional
@Service("followingService")
public class FollowingServiceImpl extends ServiceImpl<FollowingDao, Following> implements FollowingService {

    @Autowired
    private FollowingDao followingDao;

    @Override
    public Boolean queryByUserIdAndVideoId(Integer uid, Integer videoUserId) {
        LambdaQueryWrapper<Following> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Following::getUid, uid);
        queryWrapper.eq(Following::getFollowingId, videoUserId);
        Following following = followingDao.selectOne(queryWrapper);
        //是否关注
        Boolean b = false;
        if (following != null) {
            //关注
            b = true;
        }
        return b;
    }

    @Override
    public List<Integer> queryAllByUserId(Integer uid) {
        LambdaQueryWrapper<Following> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Following::getUid, uid);
        List<Following> followings = followingDao.selectList(queryWrapper);
        List<Integer> list = new ArrayList<>();
        for (Following following : followings) {
            //当前用户关注的人
            list.add(following.getFollowingId());
        }
        return list;
    }
}

